home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / applications / databases / fbase106.lha / FBase / FBaseSrc.lha / Action.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  19.6 KB  |  754 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1993 by Amit Fridman
  4.  *
  5.  *    Name .....: Action.c
  6.  *    Created ..: Tuesday 14-Dec-93 11:39:36
  7.  *    Revision .: 5
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    13-May-94   Amit Fridman           v1.05 Preliminary release
  12.  *    15-Apr-94   Amit Fridman           v1.04 Beta version complete
  13.  *    24-Mar-94   Amit Fridman           v1.03 Added Keys
  14.  *    24-Feb-94   Amit Fridman           v1.02
  15.  *    07-Jan-94   Amit Fridman           v1.01
  16.  *    14-Dec-93   Amit Fridman           Created this file!
  17.  *
  18.  * $Revision Header ********************************************************/
  19. #define REVISION    5
  20.  
  21. /* Handle FBase commands */
  22.  
  23. #include "FBase.h"
  24. #include "Protos.h"
  25.  
  26. extern Object *App;
  27. extern Object *WI_Main,*WI_Contents,*WI_View,*WI_Rename,*WI_Remark,*WI_Match;
  28. extern Object *WI_Files,*WI_Keys,*WI_KeySearch,*WI_RecKeys,*WI_FileInfo;
  29. extern Object *LV_Floppies,*LV_Contents,*LV_View,*LV_Files,*LV_FileKeys;
  30. extern Object *LV_Keys,*LV_KSSrc,*LV_KSDest,*LV_RKSrc,*LV_RKDest;
  31. extern Object *BT_Delete,*BT_Rename,*BT_ConOK,*BT_ConCancel;
  32. extern Object *BT_KeysAdd;
  33. extern Object *ST_Rename,*ST_Remark,*ST_Match,*ST_KeyName;
  34. extern Object *CM_Case,*CM_Dirs,*CM_Keys,*CM_KeyAnd;
  35. extern Object *CY_Disks;
  36. extern Object *TX_FileName,*TX_FileSize,*TX_FileRem;
  37.  
  38. extern char *CY_Labels[];
  39.  
  40. extern struct List FloppyList;
  41.  
  42. extern BOOL DataChanged;
  43.  
  44. FLOPPY *MainFloppy   = NULL;
  45. FLOPPY *BackupFloppy = NULL;
  46. RECORD *MainRecord   = NULL;
  47. RECORD *BackupRecord = NULL;
  48.  
  49. Object *ParentWindow;
  50.  
  51. STRPTR   OldKey;
  52. BOOL     NewFloppy  = FALSE;
  53. BOOL     KeysFull   = FALSE;
  54. BOOL     AddKey;
  55. BOOL     EditKey;
  56. LONGBITS CurKeyMask = 0L;
  57.  
  58. void DoReadFloppy()
  59. {
  60.    FLOPPY *Floppy,*FList,*Scan;
  61.    RECORD *OldHead,*NewHead;
  62.    ULONG   disk;
  63.    LONG    Response;
  64.    int     i;
  65.    BOOL    Exists = FALSE;
  66.  
  67.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  68.    get(CY_Disks,MUIA_Cycle_Active,&disk);
  69.     if (!ReadFloppy(CY_Labels[disk],&Floppy)) {
  70.        set(WI_Main,MUIA_Window_Sleep,FALSE);
  71.        return;
  72.     }
  73.     NewHead=Floppy->HeadRecord;
  74.     FList=(FLOPPY *)FloppyList.lh_Head;
  75.     while ((!Exists) && (((struct Node *)FList)->ln_Succ)) {
  76.        OldHead=FList->HeadRecord;
  77.        if (strcmp(NewHead->FName,OldHead->FName)==0)
  78.           Exists=TRUE;
  79.        else
  80.          FList=(FLOPPY *)(((struct Node *)FList)->ln_Succ);
  81.    }
  82.    if (Exists) {
  83.       Response=MUI_Request(App,NULL,0,"Read","*By Path|By Name|  New  |  No  ","Floppy Exists - Update?");
  84.       if (!Response) {
  85.          FreeFloppy(Floppy,FALSE);
  86.          set(WI_Contents,MUIA_Window_Open,FALSE);
  87.          set(WI_Main,MUIA_Window_Sleep,FALSE);
  88.          return;
  89.       }
  90.       if (Response<3)
  91.          SalvageData(Floppy,FList,Response);
  92.       for (i=0; ; i++) {
  93.          DoMethod(LV_Floppies,MUIM_List_GetEntry,i,&Scan);
  94.          if (Scan==FList) {
  95.             DoMethod(LV_Floppies,MUIM_List_Remove,i);
  96.             break;
  97.          }
  98.       }
  99.       Remove((struct Node*)FList);
  100.       BackupFloppy=FList;
  101.    } else
  102.         BackupFloppy=NULL;
  103.  
  104.     CreateList(LV_Contents,&Floppy->Records);
  105.    set(WI_Contents,MUIA_Window_Open,TRUE);
  106.     MainFloppy=Floppy;
  107.     NewFloppy=TRUE;
  108. }
  109.  
  110. void DoAddFloppy()
  111. {
  112.    if (NewFloppy) {
  113.        AddFloppyInPlace(&FloppyList,(struct Node *)MainFloppy);
  114.        DoMethod(LV_Floppies,MUIM_List_Insert,&MainFloppy,1,MUIV_List_Insert_Sorted);
  115.        NewFloppy=FALSE;
  116.     }
  117.     if (BackupFloppy)
  118.         FreeFloppy(BackupFloppy,FALSE);
  119.     set(WI_Contents,MUIA_Window_Open,FALSE);
  120.     set(WI_Main,MUIA_Window_Sleep,FALSE);
  121.    DataChanged=TRUE;
  122. }
  123.  
  124. void DoNoAddFloppy()
  125. {
  126.    LONG Active;
  127.  
  128.     if (NewFloppy) {
  129.        NewFloppy=FALSE;
  130.        FreeFloppy(MainFloppy,FALSE);
  131.        if (BackupFloppy) {
  132.           DoMethod(LV_Floppies,MUIM_List_Insert,&BackupFloppy,1,MUIV_List_Insert_Sorted);
  133.            AddFloppyInPlace(&FloppyList,(struct Node *)BackupFloppy);
  134.        }
  135.     } else {
  136.        if (BackupFloppy) {
  137.           get(LV_Floppies,MUIA_List_Active,&Active);
  138.           set(LV_Floppies,MUIA_List_Active,MUIV_List_Active_Off);
  139.           DoMethod(LV_Floppies,MUIM_List_Remove,Active);
  140.           DoMethod(LV_Floppies,MUIM_List_Insert,&BackupFloppy,1,MUIV_List_Insert_Sorted);
  141.            AddFloppyInPlace(&FloppyList,(struct Node *)BackupFloppy);
  142.         }
  143.     }
  144.    set(WI_Contents,MUIA_Window_Open,FALSE);
  145.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  146. }
  147.  
  148. void StopView()
  149. {
  150.    set(WI_View,MUIA_Window_Open,FALSE);
  151.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  152. }
  153.  
  154. void DoEditFloppy()
  155. {
  156.    DoMethod(LV_Floppies,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&MainFloppy);
  157.     if (!MainFloppy) return;
  158.     BackupFloppy=DupFloppy(MainFloppy);
  159.     CreateList(LV_Contents,&MainFloppy->Records);
  160.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  161.    set(WI_Contents,MUIA_Window_Open,TRUE);
  162. }
  163.  
  164. void DoDeleteRecord()
  165. {
  166.    LONG Response;
  167.    LONG id      = -1;
  168.    BOOL changed = FALSE;
  169.  
  170.    FOREVER {
  171.       DoMethod(LV_Contents,MUIM_List_NextSelected,&id);
  172.       if (id==-1) break;
  173.       DoMethod(LV_Contents,MUIM_List_GetEntry,id,&MainRecord);
  174.       if (MainRecord->Flags & RECORD_ROOT) {
  175.          MUI_Request(App,NULL,0,"Delete","*OK","Use 'Kill Floppy' instead");
  176.          return;
  177.       }
  178.       if (MainRecord->Flags & RECORD_DIRECTORY) {
  179.          Response=MUI_Request(App,NULL,0,"Delete"," Yes |Only Below|* No ","Delete directory and below?");
  180.          if (Response==0)
  181.             return;
  182.          if (Response==1)
  183.             DeleteBelow(MainRecord,TRUE);
  184.          else
  185.             DeleteBelow(MainRecord,FALSE);
  186.       } else
  187.          DeleteRecord(MainRecord);
  188.  
  189.       changed=TRUE;
  190.    }
  191.    if (changed) {
  192.       CreateList(LV_Contents,&MainFloppy->Records);
  193.       DataChanged=TRUE;
  194.    }
  195. }
  196.  
  197. void DoFind()
  198. {
  199.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  200.    set(WI_Match,MUIA_Window_Open,TRUE);
  201.    set(WI_Match,MUIA_Window_ActiveObject,ST_Match);
  202. }
  203.  
  204. void DoMatch()
  205. {
  206.    STRPTR   MatchString;
  207.    LONG     MatchULFlag;
  208.    LONG     DoDirsFlag;
  209.    LONG     DoKeysFlag;
  210.    LONG     KeyAndFlag;
  211.     BOOL     Found;
  212.     LONGBITS KeyMask;
  213.  
  214.    get(ST_Match,MUIA_String_Contents,&MatchString);
  215.    if (MatchString[0]==0) {
  216.       set(WI_Match,MUIA_Window_Open,FALSE);
  217.       set(WI_Main,MUIA_Window_Sleep,FALSE);
  218.       return;
  219.    }
  220.    set(WI_Match,MUIA_Window_Open,FALSE);
  221.     get(CM_Case,MUIA_Selected,&MatchULFlag);
  222.     get(CM_Dirs,MUIA_Selected,&DoDirsFlag);
  223.     get(CM_Keys,MUIA_Selected,&DoKeysFlag);
  224.     get(CM_KeyAnd,MUIA_Selected,&KeyAndFlag);
  225.     if (DoKeysFlag)
  226.        KeyMask=CurKeyMask;
  227.     else
  228.        KeyMask=0L;
  229.     DoMethod(LV_Files,MUIM_List_Clear,TRUE);
  230.     Found=FindMatch(&FloppyList,MatchString,MatchULFlag,DoDirsFlag,
  231.                     KeyMask,KeyAndFlag);
  232.     if (!Found) {
  233.        set(WI_Main,MUIA_Window_Sleep,FALSE);
  234.        MUI_Request(App,NULL,0,"Find","*OK","No Match Found");
  235.     } else
  236.        set(WI_Files,MUIA_Window_Open,TRUE);
  237. }
  238.  
  239. void AddMatchToList(RECORD *Record)
  240. {
  241.    DoMethod(LV_Files,MUIM_List_Insert,&Record,1,MUIV_List_Insert_Bottom);
  242. }
  243.  
  244. void DoNoMatch()
  245. {
  246.    set(WI_Match,MUIA_Window_Open,FALSE);
  247.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  248. }
  249.  
  250. void FileDispClose()
  251. {
  252.    set(WI_Files,MUIA_Window_Open,FALSE);
  253.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  254. }
  255.  
  256. void DoKillFloppy()
  257. {
  258.    LONG Response;
  259.    LONG id      = -1;
  260.    BOOL changed = FALSE;
  261.  
  262.    FOREVER {
  263.       DoMethod(LV_Floppies,MUIM_List_NextSelected,&id);
  264.       if (id==-1) break;
  265.       DoMethod(LV_Floppies,MUIM_List_GetEntry,id,&MainFloppy);
  266.  
  267.       Response=MUI_Request(App,NULL,0,"Kill Floppy","Yes|*No","Kill %s?",
  268.                            MainFloppy->HeadRecord->FName);
  269.        if (Response) {
  270.           set(WI_Main,MUIA_Window_Sleep,TRUE);
  271.            FreeFloppy(MainFloppy,TRUE);
  272.            set(WI_Main,MUIA_Window_Sleep,FALSE);
  273.            changed=TRUE;
  274.        }
  275.    }
  276.     if (changed) {
  277.       CreateList(LV_Floppies,&FloppyList);
  278.        DataChanged=TRUE;
  279.     }
  280. }
  281.  
  282. void DoViewFloppy()
  283. {
  284.    DoMethod(LV_Floppies,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&MainFloppy);
  285.     if (!MainFloppy) return;
  286.     CreateList(LV_View,&MainFloppy->Records);
  287.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  288.    set(WI_View,MUIA_Window_Open,TRUE);
  289. }
  290.  
  291. void DoNew()
  292. {
  293.    LONG Response;
  294.  
  295.    Response=MUI_Request(App,NULL,0,NULL,"Yes|*No","Clear All Data?");
  296.     if (Response) {
  297.        set(WI_Main,MUIA_Window_Sleep,TRUE);
  298.        FreeKeys();
  299.         FreeAllFloppies(&FloppyList);
  300.         DoMethod(LV_Floppies,MUIM_List_Clear,NULL);
  301.         set(WI_Main,MUIA_Window_Sleep,FALSE);
  302.         DataChanged=TRUE;
  303.     }
  304. }
  305.  
  306. void DoRenameRecord()
  307. {
  308.    DoMethod(LV_Contents,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&MainRecord);
  309.     if (!MainRecord) return;
  310.     if (MainRecord->Flags & RECORD_ROOT) {
  311.        MUI_Request(App,NULL,0,"Rename","*OK","Cannot rename Root");
  312.        return;
  313.     }
  314.    set(ST_Rename,MUIA_String_Contents,MainRecord->FName);
  315.    set(WI_Contents,MUIA_Window_Sleep,TRUE);
  316.    set(WI_Rename,MUIA_Window_Open,TRUE);
  317.    set(WI_Rename,MUIA_Window_ActiveObject,ST_Rename);
  318. }
  319.  
  320. void DoNewName()
  321. {
  322.     RECORD *Record;
  323.     STRPTR  Str;
  324.     UWORD   len;
  325.  
  326.    get(ST_Rename,MUIA_String_Contents,&Str);
  327.     len=strlen(Str);
  328.     if (len) {
  329.         Record=DupRecord(MainRecord);
  330.         DeleteRecord(MainRecord);
  331.         if (Record->FName)
  332.             FreeMem(Record->FName,strlen(Record->FName)+1);
  333.         Record->FName=AllocMem(len+1,MEMF_CLEAR);
  334.         strcpy((char *)Record->FName,Str);
  335.         if (AddRecordInPlace(&MainFloppy->Records,(struct Node *)Record,
  336.                                     (struct Node *)Record->Parent))
  337.             Record->Parent->Sub=Record;
  338.        CreateList(LV_Contents,&MainFloppy->Records);
  339.        DataChanged=TRUE;
  340.     }
  341.    set(WI_Contents,MUIA_Window_Sleep,FALSE);
  342.    set(WI_Rename,MUIA_Window_Open,FALSE);
  343. }
  344.  
  345. void DoNoNewName()
  346. {
  347.    set(WI_Contents,MUIA_Window_Sleep,FALSE);
  348.    set(WI_Rename,MUIA_Window_Open,FALSE);
  349. }
  350.  
  351. BOOL ConfirmQuit()
  352. {
  353.     return((BOOL)MUI_Request(App,NULL,0,"Quit","Yes|*No","Data Changed - Are You Sure?"));
  354. }
  355.  
  356. char *BuildName(RECORD *Record,char *Name)
  357. {
  358.    char Temp[108];
  359.  
  360.    Name[0]=0;
  361.    while (!(Record->Flags & RECORD_ROOT)) {
  362.       strcpy(Temp,Name);
  363.       strcpy(Name,Record->FName);
  364.       if (Record->Flags & RECORD_DIRECTORY)
  365.          strcat(Name,"/");
  366.       strcat(Name,Temp);
  367.       Record=Record->Parent;
  368.    }
  369.    strcpy(Temp,Name);
  370.    strcpy(Name,Record->FName);
  371.    strcat(Name,":");
  372.    strcat(Name,Temp);
  373.    return(Name);
  374. }
  375.  
  376. void CreateList(APTR LView,struct List *FList)
  377. {
  378.    struct Node *Node;
  379.  
  380.    set(LView,MUIA_List_Quiet,TRUE);
  381.    DoMethod(LView,MUIM_List_Clear,NULL);
  382.    Node=FList->lh_Head;
  383.    while (Node->ln_Succ) {
  384.       DoMethod(LView,MUIM_List_Insert,&Node,1,MUIV_List_Insert_Bottom);
  385.       Node=Node->ln_Succ;
  386.    }
  387.    set(LView,MUIA_List_Quiet,FALSE);
  388. }
  389.  
  390. void DoAbout()
  391. {
  392.    MUI_Request(App,NULL,0,NULL,"*Wow!","\33cFBase V1.06\n\33cby Amit Fridman\n\33c09.07.94");
  393. }
  394.  
  395. void DoKeys()
  396. {
  397.    STRPTR *Key;
  398.    WORD    Dummy;
  399.  
  400.    set(ST_KeyName,MUIA_Disabled,TRUE);
  401.    set(WI_Keys,MUIA_Window_ActiveObject,MUIV_Window_ActiveObject_None);
  402.    ClearKeyLView();
  403.    InitKeyScan();
  404.    while (Key=GetNextKey(&Dummy))
  405.       DoMethod(LV_Keys,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  406.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  407.    set(WI_Keys,MUIA_Window_Open,TRUE);
  408.    if (KeysFull)
  409.       set(BT_KeysAdd,MUIA_Disabled,TRUE);
  410.    CopyFromKeys();
  411.    AddKey=EditKey=FALSE;
  412. }
  413.  
  414. void KeysAccept()
  415. {
  416.    set(WI_Keys,MUIA_Window_Sleep,TRUE);
  417.    TestKeyDelete();
  418.    set(WI_Keys,MUIA_Window_Sleep,FALSE);
  419.    FreeKeyCopy();
  420.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  421.    set(WI_Keys,MUIA_Window_Open,FALSE);
  422.    DataChanged=TRUE;
  423. }
  424.  
  425. void KeysClose()
  426. {
  427.    CopyToKeys();
  428.    FreeKeyCopy();
  429.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  430.    set(WI_Keys,MUIA_Window_Open,FALSE);
  431. }
  432.  
  433. void DoAddKey()
  434. {
  435.    set(ST_KeyName,MUIA_Disabled,FALSE);
  436.    set(ST_KeyName,MUIA_String_Contents,"");
  437.    set(WI_Keys,MUIA_Window_ActiveObject,ST_KeyName);
  438.    AddKey=TRUE;
  439. }
  440.  
  441. void DoDelKey()
  442. {
  443.    STRPTR KName;
  444.    LONG   Active;
  445.  
  446.    get(LV_Keys,MUIA_List_Active,&Active);
  447.    if (Active!=MUIV_List_Active_Off) {
  448.       DoMethod(LV_Keys,MUIM_List_GetEntry,Active,&KName);
  449.       DelKeyFromList(KName);
  450.       set(LV_Keys,MUIA_List_Active,MUIV_List_Active_Off);
  451.       DoMethod(LV_Keys,MUIM_List_Remove,Active);
  452.       set(ST_KeyName,MUIA_String_Contents,"");
  453.       set(ST_KeyName,MUIA_Disabled,TRUE);
  454.       if (KeysFull) {
  455.          set(BT_KeysAdd,MUIA_Disabled,FALSE);
  456.          KeysFull=FALSE;
  457.       }
  458.       EditKey=FALSE;
  459.    }
  460. }
  461.  
  462. void DoNameKey()
  463. {
  464.    STRPTR  KName;
  465.    STRPTR *NewKey;
  466.    LONG    Active;
  467.  
  468.    if (AddKey) {
  469.       get(ST_KeyName,MUIA_String_Contents,&KName);
  470.       if (KName[0]==0) {
  471.          set(ST_KeyName,MUIA_Disabled,TRUE);
  472.          AddKey=FALSE;
  473.          return;
  474.       }
  475.       NewKey=AddKeyToList(KName,&KeysFull);
  476.       if (KeysFull)
  477.          set(BT_KeysAdd,MUIA_Disabled,TRUE);
  478.       DoMethod(LV_Keys,MUIM_List_Insert,NewKey,1,MUIV_List_Insert_Sorted);
  479.       set(ST_KeyName,MUIA_String_Contents,"");
  480.       set(ST_KeyName,MUIA_Disabled,TRUE);
  481.       AddKey=FALSE;
  482.    } else if (EditKey) {
  483.       get(ST_KeyName,MUIA_String_Contents,&KName);
  484.       if (KName[0]==0) {
  485.          set(ST_KeyName,MUIA_Disabled,TRUE);
  486.          EditKey=FALSE;
  487.          return;
  488.       }
  489.       NewKey=ChangeKeyList(OldKey,KName);
  490.       get(LV_Keys,MUIA_List_Active,&Active);
  491.       set(LV_Keys,MUIA_List_Active,MUIV_List_Active_Off);
  492.       DoMethod(LV_Keys,MUIM_List_Remove,Active);
  493.       DoMethod(LV_Keys,MUIM_List_Insert,NewKey,1,MUIV_List_Insert_Sorted);
  494.       set(ST_KeyName,MUIA_String_Contents,"");
  495.       set(ST_KeyName,MUIA_Disabled,TRUE);
  496.       EditKey=FALSE;
  497.    }
  498. }
  499.  
  500. void DoKeysChange()
  501. {
  502.    STRPTR KName;
  503.  
  504.    DoMethod(LV_Keys,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&KName);
  505.    if (KName) {
  506.       set(ST_KeyName,MUIA_Disabled,FALSE);
  507.       set(ST_KeyName,MUIA_String_Contents,KName);
  508.       set(WI_Keys,MUIA_Window_ActiveObject,ST_KeyName);
  509.       OldKey=KName;
  510.       EditKey=TRUE;
  511.    }
  512. }
  513.  
  514. void DoKeySearch()
  515. {
  516.    STRPTR *Key;
  517.    WORD    Dummy;
  518.  
  519.    DoMethod(LV_KSSrc,MUIM_List_Clear,NULL);
  520.    DoMethod(LV_KSDest,MUIM_List_Clear,NULL);
  521.    InitKeyScan();
  522.    while (Key=GetNextKey(&Dummy))
  523.       if (CurKeyMask & (1<<KeyNumber(*Key)))
  524.          DoMethod(LV_KSDest,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  525.       else
  526.          DoMethod(LV_KSSrc,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  527.    set(WI_Match,MUIA_Window_Sleep,TRUE);
  528.    set(WI_KeySearch,MUIA_Window_Open,TRUE);
  529. }
  530.  
  531. void KeySearchClose()
  532. {
  533.     STRPTR Key;
  534.     int    i;
  535.  
  536.    for (i=0,CurKeyMask=0L; ; i++) {
  537.       DoMethod(LV_KSDest,MUIM_List_GetEntry,i,&Key);
  538.       if (!Key) break;
  539.       CurKeyMask|=1<<KeyNumber(Key);
  540.    }
  541.    set(WI_Match,MUIA_Window_Sleep,FALSE);
  542.    set(WI_KeySearch,MUIA_Window_Open,FALSE);
  543. }
  544.  
  545. void KeySearchSToD()
  546. {
  547.    STRPTR KName;
  548.    LONG   id;
  549.  
  550.    FOREVER {
  551.       id=-1;
  552.       DoMethod(LV_KSSrc,MUIM_List_NextSelected,&id);
  553.       if (id==-1) break;
  554.       DoMethod(LV_KSSrc,MUIM_List_GetEntry,id,&KName);
  555.       set(LV_KSSrc,MUIA_List_Active,MUIV_List_Active_Off);
  556.       DoMethod(LV_KSSrc,MUIM_List_Remove,id);
  557.       DoMethod(LV_KSDest,MUIM_List_Insert,&KName,1,MUIV_List_Insert_Sorted);
  558.    }
  559. }
  560.  
  561. void KeySearchDToS()
  562. {
  563.    STRPTR KName;
  564.    LONG   id;
  565.  
  566.    FOREVER {
  567.       id=-1;
  568.       DoMethod(LV_KSDest,MUIM_List_NextSelected,&id);
  569.       if (id==-1) break;
  570.       DoMethod(LV_KSDest,MUIM_List_GetEntry,id,&KName);
  571.       set(LV_KSDest,MUIA_List_Active,MUIV_List_Active_Off);
  572.       DoMethod(LV_KSDest,MUIM_List_Remove,id);
  573.       DoMethod(LV_KSSrc,MUIM_List_Insert,&KName,1,MUIV_List_Insert_Sorted);
  574.    }
  575. }
  576.  
  577. void DoRecordKeys()
  578. {
  579.    STRPTR *Key;
  580.    WORD    Dummy;
  581.  
  582.    DoMethod(LV_Contents,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&MainRecord);
  583.     if (!MainRecord) return;
  584.    DoMethod(LV_RKSrc,MUIM_List_Clear,NULL);
  585.    DoMethod(LV_RKDest,MUIM_List_Clear,NULL);
  586.    InitKeyScan();
  587.    while (Key=GetNextKey(&Dummy))
  588.       if (MainRecord->Keys & (1<<KeyNumber(*Key)))
  589.          DoMethod(LV_RKDest,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  590.       else
  591.          DoMethod(LV_RKSrc,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  592.    set(WI_Contents,MUIA_Window_Sleep,TRUE);
  593.    set(WI_RecKeys,MUIA_Window_Open,TRUE);
  594.  
  595. }
  596.  
  597. void RecordKeysAccept()
  598. {
  599.     STRPTR   Key;
  600.     LONGBITS OldKeys,NewKeys;
  601.     LONGBITS AddMask,RemMask;
  602.     LONG     Response;
  603.     int      i;
  604.  
  605.    for (i=0,NewKeys=0L; ; i++) {
  606.       DoMethod(LV_RKDest,MUIM_List_GetEntry,i,&Key);
  607.       if (!Key) break;
  608.       NewKeys|=1<<KeyNumber(Key);
  609.    }
  610.    if (MainRecord->Flags & RECORD_DIRECTORY) {
  611.       Response=MUI_Request(App,NULL,0,"Keys","*Change|Copy|No","Propagate Keys Below?");
  612.       if (Response) {
  613.          if (Response==2) {
  614.             AddMask=NewKeys;
  615.             RemMask=NewKeys;
  616.          } else {
  617.             OldKeys=MainRecord->Keys;
  618.             AddMask=~((~NewKeys) | OldKeys);
  619.             RemMask=(~OldKeys) | NewKeys;
  620.          }
  621.          KeysBelow(MainRecord->Sub,AddMask,RemMask);
  622.       }
  623.    }
  624.    MainRecord->Keys=NewKeys;
  625.    set(WI_Contents,MUIA_Window_Sleep,FALSE);
  626.    set(WI_RecKeys,MUIA_Window_Open,FALSE);
  627.    DataChanged=TRUE;
  628. }
  629.  
  630. void RecordKeysClose()
  631. {
  632.    set(WI_Contents,MUIA_Window_Sleep,FALSE);
  633.    set(WI_RecKeys,MUIA_Window_Open,FALSE);
  634. }
  635.  
  636. void RecordKeysSToD()
  637. {
  638.    STRPTR KName;
  639.    LONG   id;
  640.  
  641.    FOREVER {
  642.       id=-1;
  643.       DoMethod(LV_RKSrc,MUIM_List_NextSelected,&id);
  644.       if (id==-1) break;
  645.       DoMethod(LV_RKSrc,MUIM_List_GetEntry,id,&KName);
  646.       set(LV_RKSrc,MUIA_List_Active,MUIV_List_Active_Off);
  647.       DoMethod(LV_RKSrc,MUIM_List_Remove,id);
  648.       DoMethod(LV_RKDest,MUIM_List_Insert,&KName,1,MUIV_List_Insert_Sorted);
  649.    }
  650. }
  651.  
  652. void RecordKeysDToS()
  653. {
  654.    STRPTR KName;
  655.    LONG   id;
  656.  
  657.    FOREVER {
  658.       id=-1;
  659.       DoMethod(LV_RKDest,MUIM_List_NextSelected,&id);
  660.       if (id==-1) break;
  661.       DoMethod(LV_RKDest,MUIM_List_GetEntry,id,&KName);
  662.       set(LV_RKDest,MUIA_List_Active,MUIV_List_Active_Off);
  663.       DoMethod(LV_RKDest,MUIM_List_Remove,id);
  664.       DoMethod(LV_RKSrc,MUIM_List_Insert,&KName,1,MUIV_List_Insert_Sorted);
  665.    }
  666. }
  667.  
  668. void ClearKeyLView()
  669. {
  670.    DoMethod(LV_Keys,MUIM_List_Clear,NULL);
  671. }
  672.  
  673. void AddKeyToLView(STRPTR *Key)
  674. {
  675.    DoMethod(LV_Keys,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  676. }
  677.  
  678. void DisplayFileInfo(Object *Window, Object *ListView)
  679. {
  680.    UBYTE   Text[140],Buffer[132];
  681.    STRPTR *Key;
  682.    WORD    Dummy;
  683.  
  684.    DoMethod(ListView,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&MainRecord);
  685.    if (!MainRecord) return;
  686.    sprintf(Text,"\33iName\33n   %s",BuildName(MainRecord,Buffer));
  687.    if (MainRecord->Flags & RECORD_ROOT)
  688.       strcat(Text," \33b[root]");
  689.    else if (MainRecord->Flags & RECORD_DIRECTORY)
  690.       strcat(Text," \33b(dir)");
  691.    set(TX_FileName,MUIA_Text_Contents,Text);
  692.    if (MainRecord->Flags & RECORD_DIRECTORY)
  693.       strcpy(Text,"\33iSize\33n   -----");
  694.    else
  695.       sprintf(Text,"\33iSize\33n   %ld",MainRecord->Size);
  696.    set(TX_FileSize,MUIA_Text_Contents,Text);
  697.    if (MainRecord->FRem)
  698.       sprintf(Text,"\33iRemark\33n %s",MainRecord->FRem);
  699.    else
  700.       strcpy(Text,"\33iRemark\33n -----");
  701.    set(TX_FileRem,MUIA_Text_Contents,Text);
  702.    DoMethod(LV_FileKeys,MUIM_List_Clear,TRUE);
  703.    InitKeyScan();
  704.    while (Key=GetNextKey(&Dummy))
  705.       if (MainRecord->Keys & (1<<KeyNumber(*Key)))
  706.          DoMethod(LV_FileKeys,MUIM_List_Insert,Key,1,MUIV_List_Insert_Sorted);
  707.    set(WI_FileInfo,MUIA_Window_Open,TRUE);
  708.    set(Window,MUIA_Window_Sleep,TRUE);
  709.    ParentWindow=Window;
  710. }
  711.  
  712. void StopFileInfo()
  713. {
  714.    set(WI_FileInfo,MUIA_Window_Open,FALSE);
  715.    set(ParentWindow,MUIA_Window_Sleep,FALSE);
  716. }
  717.  
  718. void DoRemark()
  719. {
  720.    DoMethod(LV_Contents,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&MainRecord);
  721.     if (!MainRecord) return;
  722.    if (MainRecord->FRem)
  723.       set(ST_Remark,MUIA_String_Contents,MainRecord->FRem);
  724.    else
  725.       set(ST_Remark,MUIA_String_Contents,"");
  726.    set(WI_Remark,MUIA_Window_Open,TRUE);
  727.    set(WI_Contents,MUIA_Window_Sleep,TRUE);
  728.    set(WI_Remark,MUIA_Window_ActiveObject,ST_Remark);
  729. }
  730.  
  731. void SetRemark()
  732. {
  733.    STRPTR String;
  734.  
  735.    get(ST_Remark,MUIA_String_Contents,&String);
  736.    if (MainRecord->FRem) {
  737.       FreeMem(MainRecord->FRem,strlen(MainRecord->FRem)+1);
  738.       MainRecord->FRem=NULL;
  739.    }
  740.    if (strlen(String)) {
  741.       MainRecord->FRem=AllocMem(strlen(String)+1,MEMF_CLEAR);
  742.       strcpy(MainRecord->FRem,String);
  743.    }
  744.    set(WI_Remark,MUIA_Window_Open,FALSE);
  745.    set(WI_Contents,MUIA_Window_Sleep,FALSE);
  746.    DataChanged=TRUE;
  747. }
  748.  
  749. void StopRemark()
  750. {
  751.    set(WI_Remark,MUIA_Window_Open,FALSE);
  752.    set(WI_Contents,MUIA_Window_Sleep,FALSE);
  753. }
  754.